from src.core.models.dto.subscription import SubscriptionDTO
from src.database.models import Subscription


def convert_db_model_to_subscription_dto(
    subscription: Subscription, with_calendars: bool = False
) -> SubscriptionDTO:
    calendars_count = 0
    if with_calendars:
        calendars_count = len(subscription.calendars)
    return SubscriptionDTO(
        id=subscription.id,
        user_id=subscription.user_id,
        status=subscription.status,
        type=subscription.subscription_type,
        calendars_count=calendars_count,
        start_date=subscription.start_date,
        end_date=subscription.end_date,
    )
